package com.yx.changdao.common.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.yx.changdao.common.annotation.AutoFill;
import com.yx.changdao.common.annotation.Dict;
import com.yx.changdao.common.annotation.DictParam;
import com.yx.changdao.common.annotation.ExportField;
import com.yx.changdao.common.utils.SysUtils;
import com.yx.changdao.common.valid.Default;
import com.yx.changdao.common.valid.Update;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;

/**
 * 登录账户表
 *
 * @author zhangqi
 * @date 2019-11-06 11:21:05
 */
@TableName(SysUser.TABLE_NAME)

@Getter
@Setter
public class SysUser implements Serializable {
    private static final long serialVersionUID = 1L;

    public static final String TABLE_NAME = "sys_user";

    /**
     * 用户id
     */
    public static final String USER_ID = "user_id";
    /**
     * 登录账户
     */
    public static final String USERNAME = "username";
    /**
     * 账户昵称
     */
    public static final String NICKNAME = "nickname";
    /**
     * 密码
     */
    public static final String PASSWORD = "password";
    /**
     * 密码盐
     */
    public static final String SALT = "salt";
    /**
     * 头像
     */
    public static final String AVATAR = "avatar";
    /**
     * 部门id
      */
    public static final String DEP_ID = "dep_id";
    /**
     * 部门名称
     */
    public static final String DEP_NAME = "dep_name";
    /**
     * 账户状态
     */
    public static final String STATUS = "status";
    /**
     * 删除标记
     */
    public static final String DELETE_FLAG = "delete_flag";
    /**
     * 创建时间
     */
    public static final String CREATE_TIME = "create_time";
    /**
     * 创建人
     */
    public static final String CREATE_BY = "create_by";
    /**
     * 更新时间
     */
    public static final String UPDATE_TIME = "update_time";
    /**
     * 更新人
     */
    public static final String UPDATE_BY = "update_by";
    /**
     *原密码
     */
    public static final String ORIGINAL_PASSWORD ="original_password";

    /**
     *原密码
     */
    public static final String CONTACT_GROUP_NAME ="contact_group_name";

    /**
     *原密码
     */
    public static final String CONTACT_GROUP_ID ="contact_group_id";


    /**
     * 用户id
     */

    @ExportField(value = "用户id")
    @TableId(type = IdType.ASSIGN_ID)
    @NotNull(message = "用户id不能为空",groups = Update.class)
    private String userId;
    /**
     * 登录账户 非空，唯一
     */

    @Length(min = 3, max = 15, message = "用户名只能在3~15位之间",groups = {Update.class, Default.class})
    @ExportField(value = "用户名")
    private String username;

    /**
     * 账户昵称 非空
     */
    @ExportField(value = "账户昵称")
    @Length(min = 1, max = 32, message = "昵称只能在1~32位之间")
    private String nickname;
    /**
     * 密码
     */
    @Length(min = 5, max = 32, message = "密码只能在5~32位之间")
    private String password;
    /**
     * 密码盐
     */
    private String salt;
    /**
     * 头像  可空，空值时，显示前端默认头像
     */
    @ExportField("头像")
    private String avatar;

    @NotNull(message = "部门id不能为空",groups = {Update.class, Default.class})
    private Integer depId;

    /**
     * 部门名称
     */
    private String depName;
    /**
     * 账户状态 取值：1-开启；0-关闭。默认取值为1
     */
    @ExportField("账户状态")
    @Dict(dicts = {
            @DictParam(key = "1", value = "开启"),
            @DictParam(key = "0", value = "关闭")
    })
    private Integer status;
    /**
     * 删除标记 取值：1-正常；0-已删除。默认取值为1
     */
    @ExportField("删除状态")
    @Dict(dicts = {
            @DictParam(key = "1", value = "正常"),
            @DictParam(key = "0", value = "已删除")
    })
    @TableLogic(value = "1", delval = "0")
    private Integer deleteFlag;
    /**
     * 创建时间
     */
    @AutoFill
    @ExportField("创建时间")
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;
    /**
     * 创建人
     */
    @ExportField(value = "创建人", index = 1)
    @AutoFill(klass = SysUtils.class, method = "currentUserId")
    @TableField(fill = FieldFill.INSERT)
    private String createBy;
    /**
     * 更新时间
     */
    @AutoFill
    @ExportField(value = "更新时间", index = 1, dateFormat = "yyyy/MM/dd")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;
    /**
     * 更新人
     */
    @ExportField(value = "更新人", index = 4)
    @AutoFill(klass = SysUtils.class, method = "currentUserId")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private String updateBy;
    /**
     * 角色名
     */
    @TableField(exist = false)
    private String roleName;
    /**
     * 角色id
     */
    @TableField(exist = false)
    private String roleId;

    private String originalPassword;

    /**
     * 联户组名称
     */
    private String contactGroupName;

    /**
     * 联户组id
     */
    @TableField(fill = FieldFill.INSERT)
    private Integer contactGroupId;
}
